﻿#define Portrayal

using System;
using System.Collections.Generic;
using System.Text;

using System.Xml;
using System.Runtime.InteropServices;

using SuperMapLib;

namespace SDB2DM
{
    class JPGISMain : JPGISXML
    {
        protected AxSuperMapLib.AxSuperWorkspace superWksp = null;
        protected XmlNode objectNode = null;
        protected string srcPath = String.Empty;
        protected string destPath = String.Empty;
        private XmlDocument doc = null;

        public JPGISMain(XmlDocument doc, AxSuperMapLib.AxSuperWorkspace superWksp, string srcPath, string destPath)
            : base(ref doc)
        {
            this.superWksp = superWksp;
            this.srcPath = srcPath;
            this.destPath = destPath;
            this.doc = doc;
        }

        public override void BuildXML()
        {
            XmlNode GINode = null;

            //宣言
            BuildDocDeclaration();

            //ルート
            GINode = GetXMLRoot();

            //データセットのノード
            IMainNode mainNode = new DatasetNode(doc, superWksp, srcPath, destPath);
            mainNode.BuildNode(GINode);

#if portrayal
            //描画のノード
            mainNode = new PortrayalNode(doc, superWksp, srcPath, destPath);
            mainNode.BuildNode(GINode);
#endif

            XMLDoc.Save(destPath);
        }

        public override XmlNode GetXMLRoot()
        {
            XmlAttribute docAttr = null;
            XmlNode rootNode = null;

            rootNode = XMLDoc.CreateElement(Utility.CM_DOMAIN_TAG, Utility.ROOT_TAG, Utility.CM_SCHEMA_URI);
            XMLDoc.AppendChild(rootNode);

            //xmlns:jps
            docAttr = XMLDoc.CreateAttribute(Utility.NAMESPACE_TAG, Utility.CM_JPS_TAG, Utility.NAMESPACE_URI);
            docAttr.Value = Utility.JPS_URI;
            rootNode.Attributes.Append(docAttr);
            //xmlns:xsi
            docAttr = XMLDoc.CreateAttribute(Utility.NAMESPACE_TAG, Utility.XSI_TAG, Utility.NAMESPACE_URI);
            docAttr.Value = Utility.XSI_URI;
            rootNode.Attributes.Append(docAttr);
            //xmlns:xlink
            docAttr = XMLDoc.CreateAttribute(Utility.NAMESPACE_TAG, Utility.XLINK_TAG, Utility.NAMESPACE_URI);
            docAttr.Value = Utility.XLINK_URI;
            rootNode.Attributes.Append(docAttr);
            //xsi:schemaLocation
            docAttr = XMLDoc.CreateAttribute(Utility.XSI_TAG, Utility.SCHEMA_LOCATION_TAG, Utility.XSI_URI);
            docAttr.Value = Utility.SCHEMA_LOCATION_URI;
            rootNode.Attributes.Append(docAttr);
            //version
            docAttr = XMLDoc.CreateAttribute(Utility.VERSION_TAG);
            docAttr.Value = Utility.HEADER_VERSION_VALUE;
            rootNode.Attributes.Append(docAttr);
            //timeStamp
            docAttr = XMLDoc.CreateAttribute(Utility.TIMESTAMP_TAG);
            docAttr.Value = DateTime.Now.ToString();
            rootNode.Attributes.Append(docAttr);

            return rootNode;
        }
    }
}
